collectgarbage("setpause", 50)

function PW(x, y, Speed, sonarRange)
	forward(y, 0.75*Speed)
	if sonarR < (0.75*sonarRange) then
		forward(x, 0.75*Speed)
		forward(y, Speed)
	end
	if sonarL > (0.75*sonarRange) then
		repeat
			forward(x, Speed)
			forward(y, 0.75*Speed)
		until sonarL > 45 or sonarR > 45
	end

end

function lightTest(sonarF, sonarR, sonarL, Speed, sonarRange)

-- LightFinding & Object Avoidance
	stop(A)
	stop(B)
	if sonarF < sonarRange then
		backward(A, Speed)
		backward(B, Speed)
	elseif sonarR < sonarRange then
		resetRotationCount(B)
		repeat
		forward(B, 0.75*Speed) 
		until rotationCounts(B) > 365
		forward(A, Speed)
		forward(B, Speed)
	elseif sonarL < sonarRange then
		resetRotationCount(A)
		repeat
			forward(A) 
		until rotationCounts(A) > 365
		forward(A, Speed)
		forward(B, Speed)
	end
end
